import axios from "axios";
var Authorizations=[
    "563492ad6f91700001000001b8f650addd61482ba5dda021583bd4ac",
    "563492ad6f9170000100000126d41335b0dd4d9599021c83e8077d7e",
    "563492ad6f917000010000011b04bf1661d54491bf0b50833a4b1a38"
]
export function request(config){
    return new Promise((resolve,reject)=>{
        if(Authorizations.length==0){
            reject({msg:"no authorizations",code:10000});
            return;
        }
        axios({
            method: config.method||'get',
            url: config.url,
            headers:{
                Authorization:config.authorization||Authorizations[0]
            },
            data:config.data||{},
            params:config.params||{},
        }).then((info)=>{
            console.log(info,'info')
            if(info.status==200){
                resolve(info)
            }else{
                Authorizations.splice(0,1)
                resolve(request(config))
            }
        })
    })
}

export function getDataCurated(params){
    // 获取精选
    console.log(params,"params")
    return request({
        url:'https://api.pexels.com/v1/curated',
        params:params
    })
}

export function getDataFeatured(params){
    // 获取热门收藏夹
    console.log(params,"params")
    return request({
        url:'https://api.pexels.com/v1/collections/featured',
        params:params
    })
}
export function getDataFeaturedD(id,params){
    // 获取收藏夹详情
    // id (必选) 收藏夹id
    // type (可选) 类型 photos / videos
    console.log(params,"params")
    return request({
        url:`https://api.pexels.com/v1/collections/${id}`,
        params:params
    })
}
export function getDataSearch(params){
    // 搜索
    // query(必选) 查询字符串 
    // orientation(可选) 方向 landscape, portrait , square 
    // size(可选) 大小 large(24MP), medium(12MP) or small(4MP). 
    // color(可选) 颜色 16进制或者 red, orange, yellow, green, turquoise, blue, violet, pink, brown, black, gray,white
    // locale(可选) 地方 'en-US' 'pt-BR' 'es-ES' 'ca-ES' 'de-DE' 'it-IT' 'fr-FR' 'sv-SE' 'id-ID' 'pl-PL' 'ja-JP' 'zh-TW' 'zh-CN' 'ko-KR' 'th-TH' 'nl-NL' 'hu-HU' 'vi-VN' 'cs-CZ' 'da-DK' 'fi-FI' 'uk-UA' 'el-GR' 'ro-RO' 'nb-NO' 'sk-SK' 'tr-TR' 'ru-RU'.
    // page(可选) 分页
    // per_page(可选) 最大返回值
    console.log(params,"params")
    return request({
        url:'https://api.pexels.com/v1/search',
        params:params
    })
}